import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;


public class SalvarLog {
	public static void salvarLog(String filename)
	{
		try {
			FileWriter fileWriter = new FileWriter(new File(filename));
			fileWriter.write("Dados de Entrada: ");
			ArrayList<String> linhas = LerDoArquivo.ler("");
			for(String str : linhas)
			{
				fileWriter.write(str);
			}
			fileWriter.write(System.getProperty("line.separator"));
			fileWriter.write("Schedule de Saida: ");
			for(Transacao transacao : TransacaoManager.transacoes.getTransacoes())
			{
				fileWriter.write(formatarTransacao(transacao));
			}
			fileWriter.flush();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	
	private static String formatarTransacao(Transacao transacao)
	{
		String string = "";
		for(Operacao operacao : transacao.getOperacaoList())
		{
			string += getOperacaoTipo(operacao.getOperacaoTipo());
			string += transacao.getId();
			string += "(" + operacao.getDado().getIdDado() + ")";
		}
		return string;
	}
	
	private static String getOperacaoTipo(int integer)
	{
		String string = "";
		if(integer == Operacao.LEITURA)
		{
			string = "r";
		}
		else
		{
			if(integer == Operacao.ESCRITA)
			{
				string = "w";
			}
		}
		return string;
	}
}
